package com.westar.core.services;

import com.westar.base.businessUtil.DepartmentPageUtil;
import com.westar.base.model.Department;
import com.westar.core.dao.DepartmentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

@Service
public class DepartmentService {
    @Autowired
    private DepartmentDao departmentDao;

    /**
     * 初始化部门信息
     */
    public void initDepartment(String actCookie) throws IOException {
        //获取所有的部门信息
        List<Department> treeDepList = departmentDao.listTreeDep(-1);
        if(null == treeDepList || treeDepList.isEmpty()){
            //添加顶部数据
            this.addDepartment(actCookie);
        }
    }
    /**
     * 添加区域信息
     * @param actCookie
     */
    private void addDepartment(String actCookie) throws IOException {
        List<Department> departmentList = DepartmentPageUtil.queryAllDep(actCookie);
        if(null != departmentList && !departmentList.isEmpty()){
            for (Department department:  departmentList) {
                departmentDao.add(department);
            }
        }


    }
}
